package com.starhub.integration.sdk.custom.core;

import okhttp3.OkHttpClient;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

/**
 * 私有化向量模型连接器
 * @version: V1.0
 * @author: liuhf
 * @time 2025-08-08
 */
@Component
public class CustomVectorClientConnector {
    private static OkHttpClient okHttpClient;
    private static final Map<String, CustomVectorClient> clientMap = new ConcurrentHashMap<>();

    private synchronized OkHttpClient getOkHttpClient() {
        if (okHttpClient == null) {
            okHttpClient = new OkHttpClient.Builder()
                    .connectTimeout(10, TimeUnit.SECONDS)
                    .readTimeout(30, TimeUnit.SECONDS)
                    .writeTimeout(30, TimeUnit.SECONDS)
                    .build();
        }
        return okHttpClient;
    }

    /**
     * 获取私有化向量模型客户端
     * 
     * @param mark      模型标识
     * @param apiHost   API主机地址
     * @param modelName 模型名称
     * @param apiPath   API路径
     * @return 私有化向量模型客户端
     */
    public synchronized CustomVectorClient getPrivateVectorClient(String mark, String apiHost, String modelName,
            String apiPath) {
        /*
         * String clientKey = mark + "_" + apiHost + "_" + modelName;
         * PrivateVectorClient client = clientMap.get(clientKey);
         * 
         * // 如果client不存在，则重新创建
         * if (client == null) {
         * client = PrivateVectorClient.builder()
         * .okHttpClient(getOkHttpClient())
         * .apiHost(apiHost)
         * .modelName(modelName)
         * .apiPath(apiPath)
         * .build();
         * 
         * clientMap.put(clientKey, client);
         * }
         * 
         * return client;
         */
        return CustomVectorClient.builder()
                .okHttpClient(getOkHttpClient())
                .apiHost(apiHost)
                .modelName(modelName)
                .apiPath(apiPath)
                .build();
    }
}